const models = require('../models')

const ExecuteRecordModel = models.ExecuteRecord

/**
 * 基本
 */

exports.ExecuteRecordModel = ExecuteRecordModel

exports.newAndSave = function (data) {
  const ExecuteRecord = new ExecuteRecordModel(data)
  return ExecuteRecord.save()
}

exports.delete = function (query) {
  return ExecuteRecordModel.remove(query)
}

exports.batchDeleteByIds = function (ids) {
  return ExecuteRecordModel.remove({ _id: { $in: ids || [] } })
}

exports.update = function (query, data) {
  return ExecuteRecordModel.update(query, {
    $set: data
  })
}

exports.find = function (query, opt) {
  return ExecuteRecordModel.find(query, {}, opt)
}

exports.findWidthField = function (query, field, opt) {
  return ExecuteRecordModel.find(query, field || {}, opt)
}
exports.findOne = function (query) {
  return ExecuteRecordModel.findOne(query)
}

exports.findOneById = function (id) {
  return ExecuteRecordModel.findById(id)
}

exports.check = function (query, opt) {
  return ExecuteRecordModel.findOne(query, '_id', opt)
}

exports.count = function (query) {
  return ExecuteRecordModel.count(query)
}
